#!/usr/bin/perl

=head1 NAME

Swignition::DataModel::Literal - Represents an RDF literal.

=cut

package Swignition::DataModel::Literal;

use Swignition::DataModel::Node;

use constant TRUE      =>  1;
use constant FALSE     =>  0;
use strict;

our @ISA = ("Swignition::DataModel::Node");
our $VERSION = '0.1';

=head1 CONSTRUCTORS

=over

=item $node = Swignition::DataModel::Literal->new($model, $string, $dt, $lang)

Create a new node. 

=cut

sub new
{
	my $class    = shift;
	my $model    = shift;
	my $string   = shift || '';
	my $datatype = shift || undef;
	my $lang     = shift || undef;
	
	my $this = Swignition::DataModel::Node::new(__PACKAGE__, $model);
	
	$this->set_string($string);
	$this->set_datatype($datatype);
	$this->set_lang($lang);
	
	return $this;
}

=back

=head1 PUBLIC METHODS

C<Swignition::DataModel::Literal> also inherits from C<Swignition::DataModel::Node>.

=over

=item $node->string

Get the string this literal represents.

=cut

sub string
{
	my $this = shift;
	return $this->{'_'}->{'string'};
}

=item $node->set_string($string)

Set the string this literal represents.

=cut

sub set_string
{
	my $this = shift;
	my $string = shift;

	$this->{'_'}->{'string'} = $string;

	return $this;
}

=item $node->datatype

Get the datatype of this literal (if any).

=cut

sub datatype
{
	my $this = shift;
	return $this->{'_'}->{'datatype'};
}

=item $node->set_datatype($dt)

Set the datatype of this literal. May be set to undef.

=cut

sub set_datatype
{
	my $this = shift;
	my $datatype = shift;
	
	$datatype = $datatype->identity
		if ((ref $datatype)
		&& $datatype->isa('Swignition::DataModel::Node'));

	$this->{'_'}->{'datatype'} = "$datatype";

	return $this;
}

=item $node->lang

Get the language of this literal (if any).

=cut

sub lang
{
	my $this = shift;
	return $this->{'_'}->{'lang'};
}

=item $node->set_lang($lang)

Set the language of this literal. May be set to undef.

=cut

sub set_lang
{
	my $this = shift;
	my $lang = shift;

	$this->{'_'}->{'lang'} = $lang;

	return $this;
}

=item $node->mergeable($an_other)

Returns true if (theoretically) this node can be merged with another node.

=cut

sub mergeable
{
	return FALSE;
}

=back

=cut

1;

